﻿
namespace FRL.DebtChase.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;


    // Implements application logic using the DebtChaseEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class DebtChaseDomainService : LinqToEntitiesDomainService<DebtChaseEntities>
    {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'aspnet_Users' query.
        public IQueryable<aspnet_Users> GetAspnet_Users()
        {
            return this.ObjectContext.aspnet_Users;
        }

        public void InsertAspnet_Users(aspnet_Users aspnet_Users)
        {
            if ((aspnet_Users.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(aspnet_Users, EntityState.Added);
            }
            else
            {
                this.ObjectContext.aspnet_Users.AddObject(aspnet_Users);
            }
        }

        public void UpdateAspnet_Users(aspnet_Users currentaspnet_Users)
        {
            this.ObjectContext.aspnet_Users.AttachAsModified(currentaspnet_Users, this.ChangeSet.GetOriginal(currentaspnet_Users));
        }

        public void DeleteAspnet_Users(aspnet_Users aspnet_Users)
        {
            if ((aspnet_Users.EntityState == EntityState.Detached))
            {
                this.ObjectContext.aspnet_Users.Attach(aspnet_Users);
            }
            this.ObjectContext.aspnet_Users.DeleteObject(aspnet_Users);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'BankAccounts' query.
        public IQueryable<BankAccount> GetBankAccounts()
        {
            return this.ObjectContext.BankAccounts;
        }

        public void InsertBankAccount(BankAccount bankAccount)
        {
            if ((bankAccount.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(bankAccount, EntityState.Added);
            }
            else
            {
                this.ObjectContext.BankAccounts.AddObject(bankAccount);
            }
        }

        public void UpdateBankAccount(BankAccount currentBankAccount)
        {
            this.ObjectContext.BankAccounts.AttachAsModified(currentBankAccount, this.ChangeSet.GetOriginal(currentBankAccount));
        }

        public void DeleteBankAccount(BankAccount bankAccount)
        {
            if ((bankAccount.EntityState == EntityState.Detached))
            {
                this.ObjectContext.BankAccounts.Attach(bankAccount);
            }
            this.ObjectContext.BankAccounts.DeleteObject(bankAccount);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'BankAccountStatuses' query.
        public IQueryable<BankAccountStatus> GetBankAccountStatuses()
        {
            return this.ObjectContext.BankAccountStatuses;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'BankAccountTypes' query.
        public IQueryable<BankAccountType> GetBankAccountTypes()
        {
            return this.ObjectContext.BankAccountTypes;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Contacts' query.
        public IQueryable<Contact> GetContacts()
        {
            return this.ObjectContext.Contacts;
        }

        public void InsertContact(Contact contact)
        {
            if ((contact.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(contact, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Contacts.AddObject(contact);
            }
        }

        public void UpdateContact(Contact currentContact)
        {
            this.ObjectContext.Contacts.AttachAsModified(currentContact, this.ChangeSet.GetOriginal(currentContact));
        }

        public void DeleteContact(Contact contact)
        {
            if ((contact.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Contacts.Attach(contact);
            }
            this.ObjectContext.Contacts.DeleteObject(contact);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ContactAddresses' query.
        public IQueryable<ContactAddress> GetContactAddresses()
        {
            return this.ObjectContext.ContactAddresses;
        }

        public void InsertContactAddress(ContactAddress contactAddress)
        {
            if ((contactAddress.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(contactAddress, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ContactAddresses.AddObject(contactAddress);
            }
        }

        public void UpdateContactAddress(ContactAddress currentContactAddress)
        {
            this.ObjectContext.ContactAddresses.AttachAsModified(currentContactAddress, this.ChangeSet.GetOriginal(currentContactAddress));
        }

        public void DeleteContactAddress(ContactAddress contactAddress)
        {
            if ((contactAddress.EntityState == EntityState.Detached))
            {
                this.ObjectContext.ContactAddresses.Attach(contactAddress);
            }
            this.ObjectContext.ContactAddresses.DeleteObject(contactAddress);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ContactAddressStatuses' query.
        public IQueryable<ContactAddressStatus> GetContactAddressStatuses()
        {
            return this.ObjectContext.ContactAddressStatuses;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ContactAddressTypes' query.
        public IQueryable<ContactAddressType> GetContactAddressTypes()
        {
            return this.ObjectContext.ContactAddressTypes;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ContactHolidays' query.
        public IQueryable<ContactHoliday> GetContactHolidays()
        {
            return this.ObjectContext.ContactHolidays;
        }

        public void InsertContactHoliday(ContactHoliday contactHoliday)
        {
            if ((contactHoliday.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(contactHoliday, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ContactHolidays.AddObject(contactHoliday);
            }
        }

        public void UpdateContactHoliday(ContactHoliday currentContactHoliday)
        {
            this.ObjectContext.ContactHolidays.AttachAsModified(currentContactHoliday, this.ChangeSet.GetOriginal(currentContactHoliday));
        }

        public void DeleteContactHoliday(ContactHoliday contactHoliday)
        {
            if ((contactHoliday.EntityState == EntityState.Detached))
            {
                this.ObjectContext.ContactHolidays.Attach(contactHoliday);
            }
            this.ObjectContext.ContactHolidays.DeleteObject(contactHoliday);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ContactPoints' query.
        public IQueryable<ContactPoint> GetContactPoints()
        {
            return this.ObjectContext.ContactPoints;
        }

        public void InsertContactPoint(ContactPoint contactPoint)
        {
            if ((contactPoint.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(contactPoint, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ContactPoints.AddObject(contactPoint);
            }
        }

        public void UpdateContactPoint(ContactPoint currentContactPoint)
        {
            this.ObjectContext.ContactPoints.AttachAsModified(currentContactPoint, this.ChangeSet.GetOriginal(currentContactPoint));
        }

        public void DeleteContactPoint(ContactPoint contactPoint)
        {
            if ((contactPoint.EntityState == EntityState.Detached))
            {
                this.ObjectContext.ContactPoints.Attach(contactPoint);
            }
            this.ObjectContext.ContactPoints.DeleteObject(contactPoint);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ContactPointStatuses' query.
        public IQueryable<ContactPointStatus> GetContactPointStatuses()
        {
            return this.ObjectContext.ContactPointStatuses;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ContactPointTypes' query.
        public IQueryable<ContactPointType> GetContactPointTypes()
        {
            return this.ObjectContext.ContactPointTypes;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ContactStatuses' query.
        public IQueryable<ContactStatus> GetContactStatuses()
        {
            return this.ObjectContext.ContactStatuses;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ContactTypes' query.
        public IQueryable<ContactType> GetContactTypes()
        {
            return this.ObjectContext.ContactTypes;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Countries' query.
        public IQueryable<Country> GetCountries()
        {
            return this.ObjectContext.Countries;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'CountryAddressFormats' query.
        public IQueryable<CountryAddressFormat> GetCountryAddressFormats()
        {
            return this.ObjectContext.CountryAddressFormats;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'CountryProvinces' query.
        public IQueryable<CountryProvince> GetCountryProvinces()
        {
            return this.ObjectContext.CountryProvinces;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Currencies' query.
        public IQueryable<Currency> GetCurrencies()
        {
            return this.ObjectContext.Currencies;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'DcEntities' query.
        public IQueryable<DcEntity> GetDcEntities()
        {
            return this.ObjectContext.DcEntities;
        }

        public void InsertDcEntity(DcEntity dcEntity)
        {
            if ((dcEntity.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(dcEntity, EntityState.Added);
            }
            else
            {
                this.ObjectContext.DcEntities.AddObject(dcEntity);
            }
        }

        public void UpdateDcEntity(DcEntity currentDcEntity)
        {
            this.ObjectContext.DcEntities.AttachAsModified(currentDcEntity, this.ChangeSet.GetOriginal(currentDcEntity));
        }

        public void DeleteDcEntity(DcEntity dcEntity)
        {
            if ((dcEntity.EntityState == EntityState.Detached))
            {
                this.ObjectContext.DcEntities.Attach(dcEntity);
            }
            this.ObjectContext.DcEntities.DeleteObject(dcEntity);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'DcEntityRelationships' query.
        public IQueryable<DcEntityRelationship> GetDcEntityRelationships()
        {
            return this.ObjectContext.DcEntityRelationships;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'DcEntityStatuses' query.
        public IQueryable<DcEntityStatus> GetDcEntityStatuses()
        {
            return this.ObjectContext.DcEntityStatuses;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'DcEntityTypes' query.
        public IQueryable<DcEntityType> GetDcEntityTypes()
        {
            return this.ObjectContext.DcEntityTypes;
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ReusableStrings' query.
        public IQueryable<ReusableString> GetReusableStrings()
        {
            return this.ObjectContext.ReusableStrings;
        }

        public void InsertReusableString(ReusableString reusableString)
        {
            if ((reusableString.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(reusableString, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ReusableStrings.AddObject(reusableString);
            }
        }

        public void UpdateReusableString(ReusableString currentReusableString)
        {
            this.ObjectContext.ReusableStrings.AttachAsModified(currentReusableString, this.ChangeSet.GetOriginal(currentReusableString));
        }

        public void DeleteReusableString(ReusableString reusableString)
        {
            if ((reusableString.EntityState == EntityState.Detached))
            {
                this.ObjectContext.ReusableStrings.Attach(reusableString);
            }
            this.ObjectContext.ReusableStrings.DeleteObject(reusableString);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ReusableStringTypes' query.
        public IQueryable<ReusableStringType> GetReusableStringTypes()
        {
            return this.ObjectContext.ReusableStringTypes;
        }

        public void InsertReusableStringType(ReusableStringType reusableStringType)
        {
            if ((reusableStringType.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(reusableStringType, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ReusableStringTypes.AddObject(reusableStringType);
            }
        }

        public void UpdateReusableStringType(ReusableStringType currentReusableStringType)
        {
            this.ObjectContext.ReusableStringTypes.AttachAsModified(currentReusableStringType, this.ChangeSet.GetOriginal(currentReusableStringType));
        }

        public void DeleteReusableStringType(ReusableStringType reusableStringType)
        {
            if ((reusableStringType.EntityState == EntityState.Detached))
            {
                this.ObjectContext.ReusableStringTypes.Attach(reusableStringType);
            }
            this.ObjectContext.ReusableStringTypes.DeleteObject(reusableStringType);
        }

        //**********************************************************************************************************************//

        public IQueryable<Country> GetCountriesAndProvinces()
        {
            return this.ObjectContext.Countries.Include("CountryProvinces").OrderBy(op => op.Name);
        }


        public IQueryable<ReusableStringType> GetReusableStringTypesWithStrings()
        {
            return this.ObjectContext.ReusableStringTypes.Include("ReusableStrings").OrderBy(op => op.TypeId);
        }

        public DcEntity GetDcEntityAndContacts(int dcEntId)
        {
            return this.ObjectContext.DcEntities.Include("Contacts.ContactAddresses").Include("Contacts.ContactPoints").Include("Contacts.ContactHolidays").Where(op => op.EntId == dcEntId).First();
        }

    }
}


